/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistence;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;


/**
 *
 * @author ceu
 */
@Entity
public class Section implements Serializable {
   
    private static final long serialVersionUidSection = 1L;
   
    private Integer idSection;
    private Date startTime;
    private Date finishTime; 
    private Address destiny; 
    private Address origin; 
    private Worker worker; 
    private Status status; 
    private Double km;
    private Integer type_vehicule;
    private Double price;
    private List<Shipment> shipments;

    public Section( Date startTime, Date finishTime, Address destiny, Address origin, Worker worker, Status status, Double km, Integer type_vehicule, Double price) {

        this.startTime = startTime;
        this.finishTime = finishTime;
        this.destiny = destiny;
        this.origin = origin;
        this.worker = worker;
        this.status = status;
        this.km = km;
        this.type_vehicule = type_vehicule;
        this.price = price;
    }

    
    
    @JoinColumn(name = "ADDRESS_destiny", referencedColumnName = "idAddress", insertable = false, updatable = false)    
    @ManyToOne(optional = false)
    public Address getDestiny() {
        return destiny;
    }

    public void setDestiny(Address destiny) {
        this.destiny = destiny;
    }

    @Column(name="finish")
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getFinishTime() {
        return finishTime;
    }

    public void setFinishTime(Date finishTime) {
        this.finishTime = finishTime;
    }

    @Column(name="km")
    public Double getKm() {
        return km;
    }

    public void setKm(Double km) {
        this.km = km;
    }

   @JoinColumn(name = "ADDRESS_origin", referencedColumnName = "idAddress", insertable = false, updatable = false)    
   @ManyToOne(optional = false)
   public Address getOrigin() {
        return origin;
    }

    public void setOrigin(Address origin) {
        this.origin = origin;
    }

    @Column(name="price")
    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    @Column(name="start")
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    @JoinColumn(name = "status_idstatus", referencedColumnName = "idStatus", insertable = false, updatable = false)    
    @ManyToOne(targetEntity=Status.class)
    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    @Column(name="type_vehicule")
    public Integer getType_vehicule() {
        return type_vehicule;
    }

    public void setType_vehicule(Integer type_vehicule) {
        this.type_vehicule = type_vehicule;
    }
    
    @JoinColumn(name = "Worker_idWorker", referencedColumnName = "idWorker", insertable = false, updatable = false)    
    @ManyToOne
    public Worker getWorker() {
        return worker;
    }

    public void setWorker(Worker worker) {
        this.worker = worker;
    }
     
      
     @TableGenerator(
        name="sectionGen",
        table="JPA_WXS_APP_SEQUENCE_GENERATOR",
        pkColumnName="GEN_KEY",
        valueColumnName="GEN_VALUE",
        pkColumnValue="idSection",
        allocationSize=1,
        initialValue=0)
        @Id
    @GeneratedValue(strategy=GenerationType.TABLE,generator="sectionGen")
     @Column(name = "idSection", nullable = false)
    public Integer getidSection() {
        return idSection;
    }

    public void setidSection(Integer idSection) {
        this.idSection = idSection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idSection != null ? idSection.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the idSection fields are not set
        if (!(object instanceof Section)) {
            return false;
        }
        Section other = (Section) object;
        if ((this.idSection == null && other.idSection != null) || (this.idSection != null && !this.idSection.equals(other.idSection))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "persistence.section[ idSection=" + idSection + " ]";
    }
    
    
    @ManyToMany(mappedBy = "sections")
    public List<Shipment> getShipments() {
        return shipments;
    }

    public void setShipments(List<Shipment> shipments) {
        this.shipments = shipments;
    }
    
}
